

var app = getApp()

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'), //检查按钮是否可用
    detail: false,
    mgxUserInfo: {}, //页面加载完成赋值
    amount: "",
    vdisplay: "none", //动态改变样式
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    //引用使用外部js
    var loginMgx = require("../../script/loginMgx.js");
    loginMgx.loginMgx(this);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true,
    })
  },
  GetBalance: function () {
    var that = this;
    //获取远程数据
    wx.request({
      url: app.globalData.urlPath + "/api/Mangox/GetBalance",
      method: "POST",
      data: {
        Token: app.globalData.loginInfo.Token,
        //OpenID: app.globalData.openid,
        Source: app.globalData.appSource,
        Param: {
          userHash: app.globalData.userHash,
        },
      },
      success: function (res) {
        app.globalData.loginInfo.Token = res.data.TokenUpdate;
        if(res.data.Code == 0){
          console.log("get获取余数成功：" + JSON.stringify(res.data));
          that.setData({
            amount: res.data.Data,
          })
          app.globalData.loginInfo.amount = res.data.Data;
        }
      }
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   * onload后面执行
   */
  onShow: function () {    
    if(app.globalData.loginInfo){
      this.setData({
        mgxUserInfo: app.globalData.mgxUserInfo,
        amount: app.globalData.loginInfo.amount,
      })
      //登陆后，每次进入刷新
      this.GetBalance();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

})
